# -*- coding: utf-8 -*-

import py_global
import logging

logger = logging.getLogger(__name__)

global_variable = 0


def outer_function():
    """嵌套函数：外层函数"""
    # 修改全局变量需要声明global
    global global_variable
    global_variable = 1
    logger.info('global_variable=%d', global_variable)

    outer_variable = 1
    logger.info('outer_variable=%d', outer_variable)

    def inner_function():
        """嵌套函数：内层函数"""
        logger.info('global_variable=%d', global_variable)
        # logger.info('outer_variable=%d', outer_variable)
        # 内层函数解析外层函数的局部变量需要声明nonlocal
        nonlocal outer_variable
        outer_variable = 2
        logger.info('outer_variable=%d', outer_variable)

        inner_variable = 3
        logger.info('inner_variable=%d', inner_variable)

        pass

    inner_function()
    logger.info('outer_variable=%d', outer_variable)

    return


if __name__ == '__main__':
    """变量作用域"""
    logger.info('global_variable=%d', global_variable)

    outer_function()
    logger.info('global_variable=%d', global_variable)

    pass
